//
// Copyright (C) 
// 
// File: PluginMain.cpp
//
// Author: Maya Plug-in Wizard 2.0
//

#include "GoCrowdNode.h"
#include "GoCrowdCmd.h"

#include <maya/MFnPlugin.h>

MStatus initializePlugin( MObject obj )
//
//	Description:
//		this method is called when the plug-in is loaded into Maya.  It 
//		registers all of the services that this plug-in provides with 
//		Maya.
//
//	Arguments:
//		obj - a handle to the plug-in object (use MFnPlugin to access it)
//
{ 
	MStatus   status;
	MFnPlugin plugin( obj, "", "2010", "Any");

	status = plugin.registerCommand( "GoCrowdCmd", GoCrowdCmd::creator );

	if ( !status )
	{
		status.perror("registerCommand failed");
		return status;
	}

	char cmdstr[2048];
	sprintf_s(cmdstr, 2048, "$strGoCrowdPath = \"%s\";", plugin.loadPath());
	status = MGlobal::executeCommand(cmdstr, true);
	
	if ( !status )
	{
		status.perror("executeCommand failed");
		return status;
	}

	sprintf_s(cmdstr, 2048, "source \"%s/GoCrowdMenu.mel\";", plugin.loadPath());
	status = MGlobal::executeCommand(cmdstr, true);

	if ( !status )
	{
		status.perror("executeCommand failed");
		return status;
	}

	sprintf_s(cmdstr, 2048, "source \"%s/GoCrowdSetup.mel\";", plugin.loadPath());
	status = MGlobal::executeCommand(cmdstr, true);
	
	if ( !status )
	{
		status.perror("executeCommand failed");
		return status;
	}

	sprintf_s(cmdstr, 2048, "source \"%s/GoCrowdPanel.mel\";", plugin.loadPath());
	status = MGlobal::executeCommand(cmdstr, true);

	if ( !status )
	{
		status.perror("executeCommand failed");
		return status;
	}

	/*
	status = plugin.registerNode( "GoCrowdNode", GoCrowdNode::id, GoCrowdNode::creator,
		GoCrowdNode::initialize );
	if (!status) {
		status.perror("registerNode failed");
		return status;
	}
	*/

	return status;
}

MStatus uninitializePlugin( MObject obj)
//
//	Description:
//		this method is called when the plug-in is unloaded from Maya. It 
//		deregisters all of the services that it was providing.
//
//	Arguments:
//		obj - a handle to the plug-in object (use MFnPlugin to access it)
//
{
	MStatus   status;
	MFnPlugin plugin( obj );

	status = plugin.deregisterCommand( "GoCrowdCmd" );
	if ( !status )
	{
		status.perror("deregisterCommand failed");
		return status;
	}

	char cmdstr[2048];
	sprintf_s(cmdstr, 2048, "gcCleanUI();");
	status = MGlobal::executeCommand(cmdstr, true);

	if ( !status )
	{
		status.perror("executeCommand failed");
		return status;
	}

	/*
	status = plugin.deregisterNode( GoCrowdNode::id );
	if (!status) {
		status.perror("deregisterNode failed");
		return status;
	}
	*/

	return status;
}